package cn.nbt.busManage.model.vo;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import cn.nbt.busManage.model.dto.DriverDto;
import cn.nbt.busManage.model.dto.BusDto;
import cn.nbt.busManage.model.dto.ScheduleDto;
import cn.nbt.busManage.model.entity.Bus;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class DriverVo implements Serializable {
    private final ArrayList<ScheduleVo> schedules ; //司机上班表
    private final Integer id;
    private final String driverName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private final LocalDateTime birthday;
    private final String address;
    private final String cell;

    public DriverVo(DriverDto driverDto) {
        this.id = driverDto.getId();
        this.driverName=driverDto.getDriverName();
        this.birthday=driverDto.getBirthday();
        this.address=driverDto.getAddress();
        this.cell=driverDto.getCell();
        ArrayList<ScheduleVo> scheduleVos = new ArrayList<>();
        for (ScheduleDto scheduleDto : driverDto.getSchedules()) {
            ScheduleVo scheduleVo = new ScheduleVo(scheduleDto);
            scheduleVos.add(scheduleVo);
        }
        this.schedules = scheduleVos;
    }

    @JsonCreator
    public DriverVo(@JsonProperty("schedules") ArrayList<ScheduleVo> schedules,
                    @JsonProperty("id") Integer id,
                    @JsonProperty("driverName") String driverName,
                    @JsonProperty("birthday") LocalDateTime birthday,
                    @JsonProperty("address") String address,
                    @JsonProperty("cell") String cell) {
        if(schedules == null) {
            schedules = new ArrayList<>();
        }
        this.schedules = schedules;
        this.id = id;
        this.driverName = driverName;
        this.birthday = birthday;
        this.address = address;
        this.cell = cell;
    }
}
